//////////////////////////////////////////////////////////////////////////
//	Name: Safe_Utils.h
//	Purpose: Safe Utilites for releasing and deleting elements.
//	Created: October 24, 2009 - Christian Sassi
//	----SGD_UTILS was the original, no need to reinvent the wheel here.----
//////////////////////////////////////////////////////////////////////////


//	Holds utility macros for SGD.
#pragma once

//	Macro to safely Release COM Objects.
#ifndef SAFE_RELEASE
	#define SAFE_RELEASE(p)			if (p) { p->Release(); p = NULL; }
#endif

//	Macro to safely delete pointers.
#ifndef SAFE_DELETE
	#define SAFE_DELETE(p)			if (p) { delete p; p = NULL; }
#endif

//	Macro to safely delete array pointers.
#ifndef SAFE_DELETE_ARRAY
	#define SAFE_DELETE_ARRAY(p)	if (p) { delete [] p; p = NULL; }
#endif

//	Macro for reporting Wrapper errors
#ifndef DXERROR
	#define DXERROR(a)	{ OutputDebugString(a); OutputDebugString("\n"); return false; }
#endif

//////////////////////////////////////////////////////////////////////////
// DXGetError
// Purpose: Prints out the string of an error. Every possible error I could find.
// In:		int		The error code returned by a DirectX Function.
// Return: char*	The error string.
//////////////////////////////////////////////////////////////////////////
inline char *DXGetError(int error) 
{
	switch (error) 
	{

	case D3DERR_CONFLICTINGTEXTUREFILTER: return "D3DERR_CONFLICTINGTEXTUREFILTER";
	case D3DERR_CONFLICTINGTEXTUREPALETTE: return "D3DERR_CONFLICTINGTEXTUREPALETTE";
	case D3DERR_CONFLICTINGRENDERSTATE: return "D3DERR_CONFLICTINGRENDERSTATE";
	case D3DERR_TOOMANYOPERATIONS: return "D3DERR_TOOMANYOPERATIONS";
	case D3DERR_UNSUPPORTEDALPHAARG: return "D3DERR_UNSUPPORTEDALPHAARG";
	case D3DERR_UNSUPPORTEDALPHAOPERATION: return "D3DERR_UNSUPPORTEDALPHAOPERATION";
	case D3DERR_UNSUPPORTEDCOLORARG: return "D3DERR_UNSUPPORTEDCOLORARG";
	case D3DERR_UNSUPPORTEDCOLOROPERATION: return "D3DERR_UNSUPPORTEDCOLOROPERATION";
	case D3DERR_UNSUPPORTEDFACTORVALUE: return "D3DERR_UNSUPPORTEDFACTORVALUE";
	case D3DERR_UNSUPPORTEDTEXTUREFILTER: return "D3DERR_UNSUPPORTEDTEXTUREFILTER";
	case D3DERR_WRONGTEXTUREFORMAT: return "D3DERR_WRONGTEXTUREFORMAT";                         
	case D3DERR_DRIVERINTERNALERROR: return "D3DERR_DRIVERINTERNALERROR";      

	case D3DERR_NOTFOUND: return "D3DERR_NOTFOUND";                 
	case D3DERR_MOREDATA: return "D3DERR_MOREDATA";                 
	case D3DERR_DEVICELOST: return "D3DERR_DEVICELOST";               
	case D3DERR_DEVICENOTRESET: return "D3DERR_DEVICENOTRESET";           
	case D3DERR_NOTAVAILABLE: return "D3DERR_NOTAVAILABLE";             
	case D3DERR_OUTOFVIDEOMEMORY: return "D3DERR_OUTOFVIDEOMEMORY";         
	case D3DERR_INVALIDDEVICE: return "D3DERR_INVALIDDEVICE";            
	case D3DERR_INVALIDCALL: return "D3DERR_INVALIDCALL";              
	case D3DERR_DRIVERINVALIDCALL: return "D3DERR_DRIVERINVALIDCALL";        
	case D3DERR_WASSTILLDRAWING: return "D3DERR_WASSTILLDRAWING";          
	case D3DOK_NOAUTOGEN: return "D3DOK_NOAUTOGEN";                 

	case D3DXFERR_BADOBJECT: return "D3DXFERR_BADOBJECT";          
	case D3DXFERR_BADVALUE: return "D3DXFERR_BADVALUE";           
	case D3DXFERR_BADTYPE: return "D3DXFERR_BADTYPE";            
	case D3DXFERR_NOTFOUND: return "D3DXFERR_NOTFOUND";           
	case D3DXFERR_NOTDONEYET: return "D3DXFERR_NOTDONEYET";         
	case D3DXFERR_FILENOTFOUND: return "D3DXFERR_FILENOTFOUND";       
	case D3DXFERR_RESOURCENOTFOUND: return "D3DXFERR_RESOURCENOTFOUND";   
	case D3DXFERR_BADRESOURCE: return "D3DXFERR_BADRESOURCE";        
	case D3DXFERR_BADFILETYPE: return "D3DXFERR_BADFILETYPE";        
	case D3DXFERR_BADFILEVERSION: return "D3DXFERR_BADFILEVERSION";     
	case D3DXFERR_BADFILEFLOATSIZE: return "D3DXFERR_BADFILEFLOATSIZE";   
	case D3DXFERR_BADFILE: return "D3DXFERR_BADFILE";            
	case D3DXFERR_PARSEERROR: return "D3DXFERR_PARSEERROR";         
	case D3DXFERR_BADARRAYSIZE: return "D3DXFERR_BADARRAYSIZE";       
	case D3DXFERR_BADDATAREFERENCE: return "D3DXFERR_BADDATAREFERENCE";   
	case D3DXFERR_NOMOREOBJECTS: return "D3DXFERR_NOMOREOBJECTS";      
	case D3DXFERR_NOMOREDATA: return "D3DXFERR_NOMOREDATA";         
	case D3DXFERR_BADCACHEFILE: return "D3DXFERR_BADCACHEFILE";       

	case D3D_OK: return "D3D_OK. Which really means nothing is wrong. Crazy, huh?";
	case E_OUTOFMEMORY: return "E_OUTOFMEMORY";
 
 	}
	return "Unknown error occurred.";
}